import React, { useState, useEffect } from 'react'
import { Col, Form, Input, Button, Table, message, } from 'antd'
import { PageHeaderWrapper } from '@ant-design/pro-layout'
import RenderButtom from '@/components/RenderButton'
import SearchBox from '@/components/SearchBox'
import  {
  fetchFaultinessList,
} from '@/services/setting/inv'

const hasSearchBtn = JSON.parse(localStorage.getItem('hasSearchBtn'))
const statusList = {
  1: '开票中',
  2: '开票成功',
  [-2]: '开票失败',
  3: '待完善数据',
  4: '待审核',
  5: '审核失败',
  6: '作废中',
  7: '作废成功',
  8: '作废失败',
  9: '发票冲红中',
  10: '发票冲红失败',
  11: '发票冲红成功',
}
const columns = [
  {
    title: '序号',
    dataIndex: 'sort',
    key: 'sort',
    render: t => <>{t + 1}</>
  },
  {
    title: "开票门店名称",
    dataIndex: 'storeName',
    key: "storeName",
  },
  {
    title: "开票门店税号",
    dataIndex: 'storeTaxpayerNum',
    key: "storeTaxpayerNum",
  },
  {
    title: "发票税额",
    dataIndex: 'ticketTaxAmount',
    key: "ticketTaxAmount",
  },
  {
    title: "发票含税总价",
    dataIndex: 'ticketTotalAmountHasTax',
    key: "ticketTotalAmountHasTax",
  },
  {
    title: "发票类型",
    dataIndex: 'type',
    key: "type",
    render: t => <>{t == 1 ? '个人' : t == 2 ? '公司' : null}</>
  },
  {
    title: "购买者抬头名称",
    dataIndex: 'buyerTitle',
    key: "buyerTitle",
  },
  {
    title: "申请时间",
    dataIndex: 'createTime',
    key: "createTime",
  },
  {
    title: "发票种类",
    dataIndex: 'invoiceTypeCode',
    key: "invoiceTypeCode",
    render: t => {
      if (t == '004') {
        return '增值税专用发票';
      } else if (t == '007') {
          return '增值税普通发票';
      } else if (t == '026') {
          return '增值税电子发票';
      } else if (t == '025') {
          return '增值税卷式发票';
      } else if (t == '032') {
          return '区块链发票';
      } else {
          return '';
      }
    }
  },
]

const Faultiness = props => {
  const { form } = props
  const { getFieldDecorator } = form
  const [data, setData] = useState([])

  useEffect(() => {
    init()
  }, [])

  const init = async (params = {
    pageNo: 1,
    pageSize: 10,
  }) => {
    const res = await fetchFaultinessList(params)
    res.code == 0 ? setData(res.data) : message.warning(res.msg)
  }

  // 表单查询
  const handleSearch = e => {
    e.preventDefault()
    form.validateFields((err, values) => {
      console.log('Received values of form: ', values)

    })
  }
  // 表单清空
  const handleReset = e => {
    form.resetFields();
  }
  // 查询条件
  const getFields = () => {
    // return(
    //   <Col span={8}>
    //     <Form.Item label={`名称`}>
    //       {getFieldDecorator(`id`, {})
    //         (<Input />)}
    //     </Form.Item>
    //   </Col>
    // )
  }
  // 按钮处理
  const handleBtn = type => {
    
  }
  return (
    <PageHeaderWrapper>
      {/* <SearchBox handleReset={handleReset} handleSearch={handleSearch} getFields={getFields} /> */}
      <RenderButtom click={handleBtn} />
      <Table 
        columns={columns}
        dataSource={data}
      />
    </PageHeaderWrapper>
    )
}

export default Form.create()(Faultiness)
